package edu.jmu.action.sysmanage.role;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;

import edu.jmu.action.privilege.Permission;
import edu.jmu.bean.privilege.Role;
import edu.jmu.service.sysmanage.RoleService;
/**
 * 角色添加
 * @author Neal
 *
 */
@Controller 
@Scope(value="prototype")
public class AddRoleAction extends ActionSupport {
	private static final long serialVersionUID = -4002706370552463613L;
	
	@Resource
	private RoleService roleService;
	
	private Role role;

	@Validations(requiredStrings={
			@RequiredStringValidator(fieldName="role.name",message="角色名不能为空"),
			@RequiredStringValidator(fieldName="role.description",message="角色描述不能为空")
	},stringLengthFields={
			@StringLengthFieldValidator(fieldName="role.description",message="角色描述长度过长，因小于100个字符",maxLength="100")
	})
	
	@Permission(module="role",privilege="addRole",desc="添加角色")
	public String addRole(){		
		roleService.save(role);
		return SUCCESS;
	}
		
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}	
}
